<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>010.10.函数属性与方法-apply-call.html</title>
</head>
<body>
    
</body>
<script>
    "use strict";
    let obj = {}

    function sum(s1 , s2 ){
        return s1 + s2
    }
    console.log(window.sum);
    
    function sumapp02(n1,n2){
        console.log(' 02 this : ' , this);
        return sum.apply(this,arguments)
    }
    
    function sumapp03(n1,n2){
        console.log(' 03 this : ' , this);
        return sum.apply(this,[ n1,n2 ] )
    }

    console.log(sumapp02(1,2));
    console.log(sumapp03(1,2));
    
    var s02 = {
        s1: 3 ,
        s2: 4,
        sum: function (){
            return this.s1 + this.s2 
        }
    }

    console.log(s02.sum());

    var s03 = {
        s1: 10,
        s2: 20 
    }

    console.log(s02.sum.apply(s03));

    window.color = 'red'; 
    var o = { 
        color: 'blue' 
    }; 
    function sayColor() { 
        console.log(this.color); 
    } 
    let objectSayColor = sayColor.bind(o); 
    objectSayColor();


    const factorial = (function f(num) { 
        if (num <= 1) { 
        return 1; 
        } else { 
        return num * f(num - 1); 
        } 
    });

    let f03 = function f(num) { 
        if (num <= 1) { 
        return 1; 
        } else { 
        return num * f(num - 1); 
        } 
    };
    
    console.log(factorial(5));
    console.log(f03(5));
    console.log(f(5)); //  Uncaught ReferenceError: f is not defined
    // console.log(f03);
    // console.log(factorial);
</script>
</html>